package com.gw.booking.service;


import com.gw.booking.common.ApiException;
import com.gw.booking.common.MessageCode;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class CaptchaService {
    public static final String SK_CAPTCHA = "captcha";

    public void checkCaptcha(HttpServletRequest request, String captcha) {
        if (StringUtils.equalsIgnoreCase(captcha, (String)request.getSession().getAttribute(SK_CAPTCHA))) {
            request.getSession().removeAttribute(SK_CAPTCHA);
        } else {
            throw new ApiException(MessageCode.CODE_ICAPTCHA_ERROR);
        }
    }
}
